class AnnihilationManager:
    """
    This class is responsible for annihilating particles which come inside
    the boundary volume. Right now, it is only limited to dealing with convex
    boundaries.
    """
    def __init__(self,elems,cutoff_frac):
        """
        Initialization of AnnihilationManager class. 
        
        elems: list of elems representing the flow (including released blobs 
               and boundary blobs)
        """
        self.elems = elems
        self.maxvor = None
        self.cutoff_frac = cutoff_frac
    
    def annihilate(self,maxvor):
        """
        Updates self.elems in such a way that elements which have 
        vorticity less than the cutoff percent of maxvor are deleted.
        """
        
        # deleting particles below cutoff vorticity
        tobe_deleted = []
        
        for i in range(len(self.elems)):
            elem = self.elems[i]
            elemvor = elem.vor.length()
            if elemvor < self.cutoff_frac*maxvor:
                tobe_deleted.append(i) 
        
        # reverse-sorting obtained list to avoid mess up with self.elems indices
        tobe_deleted = sorted(tobe_deleted,reverse=True)
        
        for i in tobe_deleted:
            del self.elems[i]
